package com.haoniu.web.controller.module;

import com.haoniu.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.haoniu.common.annotation.Log;
import com.haoniu.common.enums.BusinessType;
import com.haoniu.module.domain.database.MerchantInfo;
import com.haoniu.module.service.MerchantInfoService;
import com.haoniu.web.core.base.BaseController;
import com.haoniu.framework.web.page.TableDataInfo;
import com.haoniu.common.base.AjaxResult;

import java.util.List;
/**
 * 商户余额账号 信息操作处理
 *
 * @author houyijun
 * @date 2019-01-28
 */
@Controller
@RequestMapping("/module/merchantInfo")
public class MerchantInfoController extends BaseController
{
    private String prefix = "module/merchantInfo";

	@Autowired
	private MerchantInfoService merchantInfoService;

	@RequiresPermissions("module:merchantInfo:view")
	@GetMapping()
	public String merchantInfo()
	{
	    return prefix + "/merchantInfo";
	}

	/**
	 * 查询商户余额账号列表
	 */
	@RequiresPermissions("module:merchantInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(MerchantInfo merchantInfo) {
		startPage();
        List<MerchantInfo> list = merchantInfoService.selectMerchantInfoList(merchantInfo);
		return getDataTable(list);
	}

	/**
	 * 新增商户余额账号
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存商户余额账号
	 */
	@RequiresPermissions("module:merchantInfo:add")
	@Log(title = "商户余额账号", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(MerchantInfo merchantInfo) {
        merchantInfo.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(merchantInfoService.insertMerchantInfo(merchantInfo));
	}

	/**
	 * 修改商户余额账号
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(id);
		mmap.put("merchantInfo", merchantInfo);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存商户余额账号
	 */
	@RequiresPermissions("module:merchantInfo:edit")
	@Log(title = "商户余额账号", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(MerchantInfo merchantInfo) {
        merchantInfo.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(merchantInfoService.updateMerchantInfo(merchantInfo));
	}

	/**
	 * 删除商户余额账号
	 */
	@RequiresPermissions("module:merchantInfo:remove")
	@Log(title = "商户余额账号", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(merchantInfoService.deleteMerchantInfoByIds(ids));
	}

}
